Skip to main content

Usage

Basic Example

import 'package:flutter/material.dart';
import 'package:trustchex_flutter_sdk/trustchex_flutter_sdk.dart';

class VerificationScreen extends StatelessWidget {
final String sessionId;
final String baseUrl;

const VerificationScreen({
super.key,
required this.sessionId,
required this.baseUrl,
});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Verification')),
body: TrustchexView(
sessionId: sessionId,
baseUrl: baseUrl,
onCompleted: () {
Navigator.of(context).pop();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Verification completed successfully!'),
backgroundColor: Colors.green,
),
);
},
onError: (error) {
Navigator.of(context).pop();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Verification error: $error'),
backgroundColor: Colors.red,
),
);
},
),
);
}
}

Props

PropTypeRequiredDescription
baseUrlStringYour API base URL
sessionIdStringSession identifier
brandingTrustchexBrandingColors and logo
localeTrustchexLocaleLanguage (en, tr)
onCompletedVoidCallbackSuccess callback
onErrorFunction(String)Error callback

With Branding

TrustchexView(
sessionId: sessionId,
baseUrl: 'https://api.trustchex.com',
locale: TrustchexLocale.en,
branding: const TrustchexBranding(
logoUrl: 'https://trustchex.com/logo.png',
primaryColor: Color(0xFF1E40AF),
secondaryColor: Color(0xFFF8FAFC),
tertiaryColor: Color(0xFFDC2626),
),
onCompleted: () {
Navigator.of(context).pop();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Verification completed successfully!'),
backgroundColor: Colors.green,
),
);
},
onError: (error) {
Navigator.of(context).pop();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Verification error: $error'),
backgroundColor: Colors.red,
),
);
},
)

Deep link functionality is an optional feature if you want to publish a standalone app. To process deep links with the SDK, you need to configure deep links in your app and set up the required hooks to handle incoming URLs.

iOS - Add to Info.plist:

<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>yourapp</string>
</array>
</dict>
</array>

Android - Add to AndroidManifest.xml:

<activity android:name=".MainActivity">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="yourapp" />
</intent-filter>
</activity>

Import and use the DeeplinkUtils class to parse incoming URLs:

import 'package:flutter/material.dart';
import 'package:trustchex_flutter_sdk/trustchex_flutter_sdk.dart';
import 'package:uni_links/uni_links.dart';

class App extends StatefulWidget {
const App({super.key});

@override
State<App> createState() => _AppState();
}

class _AppState extends State<App> {
String? baseUrl;
String? sessionId;

@override
void initState() {
super.initState();
_handleInitialLink();
_handleIncomingLinks();
}

Future<void> _handleInitialLink() async {
try {
final initialLink = await getInitialLink();
if (initialLink != null) {
_processDeepLink(initialLink);
}
} catch (e) {
print('Error handling initial link: $e');
}
}

void _handleIncomingLinks() {
linkStream.listen((String? link) {
if (link != null) {
_processDeepLink(link);
}
});
}

void _processDeepLink(String url) {
final parsed = DeeplinkUtils.parseDeepLink(url);
if (parsed != null && parsed['sessionId'] != null) {
setState(() {
baseUrl = parsed['baseUrl'] ?? 'https://api.trustchex.com';
sessionId = parsed['sessionId'];
});
}
}

@override
Widget build(BuildContext context) {
return TrustchexView(
baseUrl: baseUrl,
sessionId: sessionId,
onCompleted: () => print('Done'),
onError: (error) => print('Error: $error'),
);
}
}

The DeeplinkUtils.parseDeepLink function parses URLs with the format:

scheme://app-url/your-api.com/verification-session/session-123

And returns a map with baseUrl and sessionId keys.

note

You'll need to add the uni_links package to handle deep links:

dependencies:
uni_links: ^0.5.1

Sessions

Create sessions using the REST API.

Session Access Methods

The SDK provides multiple ways for users to access their verification session:

Users click a link that opens the app directly with the session:

// Deep link format: yourapp://app-url/your-api.com/verification-session/session-123
TrustchexView(
baseUrl: 'https://your-api.com',
sessionId: 'session-123', // From deep link
onCompleted: () => print('Done'),
)

Benefits:

  • Seamless user experience - one tap to start
  • Direct navigation to verification
  • No manual input required
  • Works great for email and SMS campaigns

Users scan a QR code that contains the session information. The SDK includes a built-in QR scanner accessible from the welcome screen.

Benefits:

  • Quick and contactless
  • No typing required
  • Ideal for in-person verification
  • Built-in scanner included in SDK

3. Session Code Entry (Alternative)

Users can manually enter an 8-character alphanumeric code:

TrustchexView(
baseUrl: 'https://your-api.com',
// No sessionId prop needed - user enters code manually
onCompleted: () => print('Done'),
)

When no sessionId is provided, the SDK displays a screen where users can:

  • Enter the 8-character session code
  • Scan a QR code

Use Cases:

  • Fallback when QR/deep link unavailable
  • Phone/voice support scenarios
  • Print media without QR capability

Creating Sessions

When creating a session via the REST API, you'll receive access methods in the response:

final response = await http.post(
Uri.parse('https://your-api.com/api/v1/verification-sessions'),
headers: {'x-api-key': 'YOUR_API_KEY'},
body: jsonEncode({
'workflowId': 'workflow-123',
'email': '[email protected]'
}),
);

final data = jsonDecode(response.body);
final deepLink = data['deepLink'];
final qrCodeLink = data['qrCodeLink'];
final sessionCode = data['sessionCode'];

// Use deepLink for direct app navigation (recommended)
// Use qrCodeLink to generate QR code (recommended)
// Use sessionCode as alternative access method